const express = require('express');
const multer = require('multer');
const cors = require('cors');

const app = express();
app.use(cors());
app.use(express.static('files'));
const storage = multer.diskStorage({
    destination: (req, file, cb) => {
        cb(null,'files')
    },
    filename:(req, file, cb) => {
        cb(null,Date.now()+'-'+file.originalname)
    },
})
const upload=multer({storage}).array('file')//.single('file');
app.post('/upload',(req,res)=>{
    upload(req,res,(err)=>{
        if (err){
            return res.status(500).json(err);
        }
        return res.status(200).send(req.files)
    })
});
app.listen(8000,()=>{
    console.log('服务器正在启动，端口8000');
})